

%% change in profits and land rents
MomentsQO.TotalProfits   / MomentsCE.TotalProfits
MomentsQO.TotalLandRents / MomentsCE.TotalLandRents

MomentsZ.TotalProfits   / MomentsCE.TotalProfits
MomentsZ.TotalLandRents / MomentsCE.TotalLandRents


%% rebating land rents to workers: adjustment factor
rebateQO  = AgLabIncome(vC,zetaC) ;
AgLabIncomeQO = AgLabIncome(vQO,zetaQO) ;
AgLabIncomeZ  = AgLabIncome(vZ,zetaZ) ;


%% compute aggregate welfare gains

Factor = 100 ;

Wg_Z  = Factor * ( MomentsZ.Welfare  ./ MomentsCE.Welfare - 1 ) ;
Wg_QO = Factor * ( MomentsQO.Welfare ./ MomentsCE.Welfare - 1 ) ;

Ug_Z  = Factor * ( MomentsZ.WM  ./ MomentsCE.WM - 1 ) ;
Ug_QO = Factor * ( MomentsQO.WM ./ MomentsCE.WM - 1 ) ;

Eg_Z  = Factor * ( ( MomentsZ.WM  .* MomentsZ.WE  ) ./ ( MomentsCE.WM .* MomentsCE.WE ) - MomentsZ.WM  ./ MomentsCE.WM ) ;
Eg_QO = Factor * ( ( MomentsQO.WM .* MomentsQO.WE ) ./ ( MomentsCE.WM .* MomentsCE.WE ) - MomentsQO.WM ./ MomentsCE.WM ) ;

Hg_Z  = Factor * ( ( MomentsZ.WM  .* MomentsZ.WE  .* MomentsZ.WH )  ./ ( MomentsCE.WM .* MomentsCE.WE .* MomentsCE.WH ) - ( MomentsZ.WM  .* MomentsZ.WE )  ./ ( MomentsCE.WM .* MomentsCE.WE ) ) ;
Hg_QO = Factor * ( ( MomentsQO.WM .* MomentsQO.WE .* MomentsQO.WH ) ./ ( MomentsCE.WM .* MomentsCE.WE .* MomentsCE.WH ) - ( MomentsQO.WM .* MomentsQO.WE ) ./ ( MomentsCE.WM .* MomentsCE.WE ) ) ;

ProfQO  = 100 * ( MomentsQO.TotalProfits   / MomentsCE.TotalProfits   -1 ) ;
RentsQO = 100 * ( MomentsQO.TotalLandRents / MomentsCE.TotalLandRents -1 ) ;

ProfZ  = 100 * ( MomentsZ.TotalProfits   / MomentsCE.TotalProfits   - 1 ) ;
RentsZ = 100 * ( MomentsZ.TotalLandRents / MomentsCE.TotalLandRents - 1 ) ;



%% write table

if options.SaveResults

    fid = fopen(['results/WelfareGains.tex'],'w');

    fprintf(fid,'\\begin{tabular}{lccc}\n');
    fprintf(fid,'                                      & Laissez-faire   & Quasi-optimal & EZ program  \\\\[1mm] \n');
    fprintf(fid,'\\hline \\\\[-1mm] \n');
    fprintf(fid,'Aggregate unemployment rate (p.p.)    & %2.2f           & %2.2f         & %2.2f       \\\\[1mm] \n' , [ 100*MomentsCE.MeanU   , 100*MomentsQO.MeanU   , 100*MomentsZ.MeanU     ] ) ;
    fprintf(fid,'St. dev. unemployment rate (p.p.)     & %2.2f           & %2.2f         & %2.2f       \\\\[1mm] \n' , [ 100*MomentsCE.StdU    , 100*MomentsQO.StdU    , 100*MomentsZ.StdU      ] ) ;
    fprintf(fid,'\\hline \\\\[-1mm] \n');
    fprintf(fid,'Worker welfare gains (\\%%)           &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     Wg_QO               , Wg_Z               ] ) ;
    fprintf(fid,'\\hskip5mm Unemployed                 &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     Ug_QO               , Ug_Z               ] ) ;
    fprintf(fid,'\\hskip5mm Employed                   &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     Eg_QO               , Eg_Z               ] ) ;
    fprintf(fid,'\\hskip5mm Human capital              &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     Hg_QO               , Hg_Z               ] ) ;
    fprintf(fid,'\\hline \\\\[-1mm] \n');
    fprintf(fid,'Profits (\\%%)                        &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     ProfQO              , ProfZ               ] ) ;
    fprintf(fid,'Land rents (\\%%)                     &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     RentsQO             , RentsZ              ] ) ;
    fprintf(fid,'\\hline \\\\[-1mm] \n');
    fprintf(fid,'Income tax (\\%%)                       &                 & %2.2f         & %2.2f       \\\\[1mm] \n' , [                     100 * MomentsQO.xi , 100 * MomentsZ.xi ] ) ;
    fprintf(fid,'\\hline\n');
    fprintf(fid,'\\end{tabular}');

    fclose(fid);

end



